package test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Random;
/**
 * @Author: suncf
 * @Data: 2023年04月29日 8:55
 * @Version: V1.0
 * @Description:TODO
 */
public class DoubleColorBallGenerator {
    private static final int RED_MIN = 1;
    private static final int RED_MAX = 33;
    private static final int BLUE_MIN = 1;
    private static final int BLUE_MAX = 16;

    private static final List<Integer[]> HISTORY_NUMBERS = Arrays.asList(
            new Integer[] { 2, 5, 11, 20, 29, 33, 16 },
            new Integer[] { 1, 7, 14, 18, 25, 29, 6 },
            new Integer[] { 3, 11, 17, 24, 32, 33, 5 },
            new Integer[] { 4, 9, 12, 14, 16, 19, 2 },
            new Integer[] { 8, 10, 13, 22, 28, 29, 15 }
            // 更多历史中奖号码...
    );

    public static void main(String[] args) {
        // 生成一组号码，并计算中奖概率
        Integer[] numbers = generateNumbers();
        double probability = calculateProbability(numbers);
        System.out.format("号码：%s，中奖概率：%.2f%%\n", Arrays.toString(numbers), probability * 100);
    }

    public static Integer[] generateNumbers() {
        // 生成6个红球号码
        List<Integer> redBalls = new ArrayList<>();
        for (int i = RED_MIN; i <= RED_MAX; i++) {
            redBalls.add(i);
        }
        Collections.shuffle(redBalls);
        Integer[] redNumbers = redBalls.subList(0, 6).toArray(new Integer[6]);
        Arrays.sort(redNumbers);

        // 生成1个蓝球号码
        Integer blueNumber = BLUE_MIN + new Random().nextInt(BLUE_MAX - BLUE_MIN + 1);

        return Arrays.copyOf(redNumbers, 7);
    }

    private static double calculateProbability(Integer[] numbers) {
        int count = 0;
        for (Integer[] history : HISTORY_NUMBERS) {
            // 统计相同的红球数量
            int sameRedBalls = 0;
            for (int i = 0; i < history.length - 1; i++) {
                if (Arrays.asList(numbers).contains(history[i])) {
                    sameRedBalls++;
                }
            }

            // 统计相同的蓝球数量
            boolean sameBlueBall = history[6].equals(numbers[6]);

            // 判断是否中奖
            if (sameRedBalls == 6 && sameBlueBall) {
                return 1.0;
            } else if (sameRedBalls == 6) {
                count++;
            }
        }
        return (double) count / HISTORY_NUMBERS.size();
    }
}
